package Q429

import java.util.*
import kotlin.collections.ArrayList

//n叉树的层序遍历
class Main {
    private fun levelOrder(root: Node2?): List<List<Int>> {
        var res = ArrayList<List<Int>>()
        var queue: Queue<Node2> = LinkedList<Node2>()
        if (root != null) {
            queue.add(root)
        }

        while (queue.isNotEmpty()) {
            var level = ArrayList<Int>()
            for(i in 0 until queue.size){
                var node = queue.poll()
                level.add(node.`val`)
                for (child in node.children!!){
                    if(child != null){
                        queue.offer(child)
                    }
                }
            }
            res.add(level)
        }
        return res
    }
}




class Node2 {
    var `val` = 0
    var children: List<Node2>? = null

    constructor() {}
    constructor(_val: Int) {
        `val` = _val
    }

    constructor(_val: Int, _children: List<Node2>?) {
        `val` = _val
        children = _children
    }
}


fun main() {

}